<template>
	<view class="content" v-cloak>
		<image :src="'/images/mybei.png' | formatImgUrl" class="bei" mode=""></image>
		<view class="top">
			<button class="head" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
				<image :src="userInfo.pic | formatImgUrl" class="head" mode=""></image>
			</button>
			<view class="tocen">
				<input type="nickname" class="nick" :value="userInfo.username?userInfo.username:'默认昵称'" maxlength="15"
					@change="bindNick" />
				<view class="jibox">
					<image
						:src="$options.filters.formatImgUrl(userInfo.writer_level.is_active?userInfo.writer_level.level.image:userInfo.writer_level.level.hide_img)"
						@click="$go('/pages/user/grade?uid='+userInfo.membe_id)" class="jipic" mode=""
						v-if="userInfo.is_writer">
					</image>
					<image
						:src="$options.filters.formatImgUrl(userInfo.user_level.is_active?userInfo.user_level.level.image:userInfo.user_level.level.hide_img)"
						class="biepic" mode="" v-if="userInfo.is_vip"></image>
				</view>
			</view>
			<view class="zhu" @click="$go('/pages/my/my')">
				<view class="zhutxt">
					主页
				</view>
				<image :src="'/images/rar.png' | formatImgUrl" class="rar" mode=""></image>
			</view>
		</view>
		<view class="shubox">
			<view class="shuli" @click="$go('/pages/user/fans')">
				<view class="shutitle">
					{{userInfo.fans_num}}
				</view>
				<view class="shutxt">
					粉丝
				</view>
			</view>
			<view class="line"></view>
			<view class="shuli" @click="$go('/pages/user/concern')">
				<view class="shutitle">
					{{userInfo.follow_num}}
				</view>
				<view class="shutxt">
					关注
				</view>
			</view>
			<view class="line"></view>
			<view class="shuli">
				<view class="shutitle">
					{{userInfo.star_num}}
				</view>
				<view class="shutxt">
					获赞
				</view>
			</view>
		</view>
		<view class="huibox" @click="$go('/pages/user/vip')">
			<view class="left">
				<view class="huititle">
					成为平台会员，多重权益享不停
				</view>
				<view class="huitxt">
					立刻查看我的平台权益有哪些
				</view>
			</view>
			<view class="see">
				我的权益
			</view>
		</view>
		<view v-if="userInfo.is_writer">
			<view class="lanbox">
				<view class="lanli" @click="$go('/pages/user/release')">
					<image :src="'/images/sa.png' | formatImgUrl" class="lanpic" mode=""></image>
					<view class="lantxt">
						我的发布
					</view>
				</view>
				<view class="lanli" @click="$go('/pages/user/order')">
					<image :src="'/images/sb.png' | formatImgUrl" class="lanpic" mode=""></image>
					<view class="lantxt">
						订单查询
					</view>
				</view>
				<view class="lanli" @click="$go('/pages/user/property')">
					<image :src="'/images/sc.png' | formatImgUrl" class="lanpic" mode=""></image>
					<view class="lantxt">
						我的资产
					</view>
				</view>
				<view class="lanli" @click="$go('/pages/user/collective')">
					<image :src="'/images/sd.png' | formatImgUrl" class="lanpic" mode=""></image>
					<view class="lantxt">
						申请入团
					</view>
				</view>
				<button class="lanli" open-type="contact">
					<image :src="'/images/se.png' | formatImgUrl" class="lanpic" mode=""></image>
					<view class="lantxt">
						联系客服
					</view>
				</button>
				<view class="lanli" @click="$go('/pages/user/yuegao')">
					<image :src="'/images/sf.png' | formatImgUrl" class="lanpic" mode=""></image>
					<view class="lantxt">
						约稿设置
					</view>
				</view>
				<view class="lanli" @click="no_go()">
					<image :src="'/images/pipei.png' | formatImgUrl" class="lanpic" mode=""></image>
					<view class="lantxt">
						匹配大厅
					</view>
				</view>
				<!-- <view class="lanli" @click="$go('/pages/user/notice')">
					<image :src="'/images/sg.png' | formatImgUrl" class="lanpic" mode=""></image>
					<view class="lantxt">
						约文须知
					</view>
				</view> -->
				<view class="lanli" @click="$go('/pages/user/set')">
					<image :src="'/images/sh.png' | formatImgUrl" class="lanpic" mode=""></image>
					<view class="lantxt">
						更多设置
					</view>
				</view>
			</view>

			<view class="adindex" :class="{isactive : userInfo.writer_user_config.order_receiving_status}">
				<view class="left">
					<view class="huititle">
						加入首页推荐，开启接单功能
					</view>
					<view class="huitxt">
						立即启用功能，享受更加完整的使用体验！
					</view>
				</view>
				<u-switch v-model="userInfo.writer_user_config.order_receiving_status" :inactiveValue="0"
					:activeValue="1" inactiveColor="#888EB6" size="20" activeColor="#7BF0D9"
					@change="change"></u-switch>
			</view>
			<view class="qbox ">
				<view class="qline"></view>
				<view class="qtitle">
					正在制作
				</view>
				<view class="seemore" @click="$go('/pages/user/order?type=2&status=2')">
					查看更多
				</view>
			</view>


			<view class="empytView" v-if="!list.total">
				<image :src="'/images/kong.png' | formatImgUrl" mode="widthFix" />
				<!-- <view>- 空列表 -</view> -->
			</view>


			<view class="dzBox" v-for="item in rowList" @click="item.is_writer==0?$go('/pages/user/orderdetail?id='+item.id):$go('/pages/my/connect?id='+item.id)">
				<view class="dztop">
					<image :src="'/images/je.png' | formatImgUrl" class="dzpic" mode=""></image>
					<view class="dztxt">
						{{item.c_title}}
					</view>
					<view class="jintxt">
						进行中
					</view>
				</view>
				<view class="uobox">
					<image :src="item.user.pic | formatImgUrl" class="uopic" mode=""></image>
					<view class="uotxt">
						订单共计{{item.price}}币
					</view>
					<!-- <view v-if="item.is_writer==1" class="goup" @click="$go('/pages/my/upload?id='+item.id)">
						去上传
					</view> -->
					<view v-if="item.is_writer==1&&item.status==1" class="goup" >
						去接单
					</view>
					<view v-if="item.is_writer==1&&item.status==2" class="goup" @click="$go('/pages/my/upload?id='+item.id)">
						去上传
					</view>
					<view  v-if="item.is_writer==1&&item.status==3"  style="width:160rpx"  class="goup">
						等待客户定稿
					</view>
					
					
					<view v-if="item.is_writer==0&&item.status==1" class="goup">
						去查看
					</view>
					<view  v-if="item.is_writer==0&&item.status==2" class="goup"  style="width:160rpx">
						待写手上传
					</view>
					<view  v-if="item.is_writer==0&&item.status==3" class="goup" @click="$go('/pages/my/check?id='+item.id)">
						去定稿
					</view>
					
				</view>
			</view>

			<!-- <view class="nomore" v-if="rowList.length && list.current_page == list.last_page">
				没有更多了~
			</view> -->
		</view>

		<view v-else>
			<view class="lanbox">
				<view class="gerenli" @click="$go('/pages/user/release')">
					<image :src="'/images/sa.png' | formatImgUrl" class="lanpic" mode=""></image>
					<view class="lantxt">
						我的发布
					</view>
				</view>
				<view class="gerenli" @click="$go('/pages/user/order')">
					<image :src="'/images/sb.png' | formatImgUrl" class="lanpic" mode=""></image>
					<view class="lantxt">
						订单查询
					</view>
				</view>
				<view class="gerenli" @click="$go('/pages/user/property')">
					<image :src="'/images/sc.png' | formatImgUrl" class="lanpic" mode=""></image>
					<view class="lantxt">
						我的资产
					</view>
				</view>
				<view class="gerenli" @click="isWriterApply()">
					<image :src="'/images/si.png' | formatImgUrl" class="lanpic" mode=""></image>
					<view class="lantxt">
						写手认证
					</view>
				</view>
				<button class="gerenli" open-type="contact">
					<image :src="'/images/se.png' | formatImgUrl" class="lanpic" mode=""></image>
					<view class="lantxt">
						联系客服
					</view>
				</button>
				<view class="gerenli" @click="$go('/pages/user/set')">
					<image :src="'/images/sh.png' | formatImgUrl" class="lanpic" mode=""></image>
					<view class="lantxt">
						更多设置
					</view>
				</view>
			</view>
			
			
			
			
		</view>
		<tabbar></tabbar>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				// 个人/写手
				personal: false,
				// 开关
				value: false,
				xuan: false,
				userInfo: this.$db.get('userInfo'),

				page: 1,
				list: {},
				rowList: []
			}
		},
		onShow() {
			this.getUserInfo()
			this.getOrderList()
		},
		onLoad() {

		},
		// 上拉加载
		onReachBottom() {
			if (this.list.current_page < this.list.last_page) {
				this.page++; // 页数加一，加载下一页数据
				this.getOrderList();
			}
		},
		methods: {
			no_go(){
				this.$common.errorToShow('暂未开放')
			},
			// 获取进行中的订单
			getOrderList() {
				
				this.$api.default.request('order/orderList_user', {
					status: 2,
					type: 2,
					page: this.page
				}, 'POST', false).then((res) => {
					if (res.code == 1) {
						this.list = res.data
						if (res.data.current_page > 1) {
							res.data.data.forEach((item) => {
								this.rowList.push(item)
							})
						} else {
							this.rowList = res.data.data
						}
					}
				})
			},

			saveWriterUserConfig() {
				var that = this
				var prams = {
					order_receiving_status: this.userInfo.writer_user_config.order_receiving_status
				}
				if (!this.userInfo.writer_user_config.hasOwnProperty('uid')) {
					prams['uid'] = this.userInfo.writer_user_config.uid
				}
				
				if (!this.userInfo.writer_user_config.word_price) {
					this.$common.errorToShow('未设置价格',()=>{
						this.userInfo.writer_user_config.order_receiving_status = 0
					},1000)
					return
				}
				// if (Array.isArray(this.userInfo.writer_diy_tags) && this.userInfo.writer_diy_tags.length === 0) {
				// 	this.$common.errorToShow('未设置标签')
				// 	return
				// }

				this.$api.default.request('good/list', {
					page: 1
				}).then((res) => {
					if (res.code) {
						if (res.data.total) {
							that.$api.default.request('user/saveWriterUserConfig', prams, 'POST', false).then((
								res) => {
									if (res.code == 1) {
										console.log(res.msg)
									} else {
										that.$common.errorToShow(res.msg, () => {
											that.userInfo.writer_user_config.order_receiving_status = 0
										})
									}
								})
						} else {
							that.$common.errorToShow('请先上传橱窗商品', () => {
								that.userInfo.writer_user_config.order_receiving_status = 0
							})

						}
					}
				})
			},
			isWriterApply() {
				if (this.userInfo.writer_apply) {
					if (this.userInfo.writer_apply.status != 2) {
						this.$go('/pages/user/examine')
					} else {
						this.$go('/pages/user/attestation')
					}
				} else {
					this.$go('/pages/user/attestation')
				}

			},
			getUserInfo() {
				this.$api.default.request('user/userInfo', {}, 'POST', false).then((res) => {
					if (res.code) {
						this.userInfo = res.user
						if (res.user.writer_user_config.hasOwnProperty('order_receiving_status')) {
							this.xuan = this.userInfo.writer_user_config.order_receiving_status
						}
					} else {
						this.$common.errorToShow(res.msg)
					}
				})
			},
			onChooseAvatar(e) {
				this.$common.uploadImg(e.detail.avatarUrl, (data) => {
					if (data) {
						this.saveUser({
							'pic': data
						})
					}
				})
			},
			bindNick(e) {
				if (e.detail.value != this.userInfo.username) {
					this.userInfo.username = e.detail.value ? e.detail.value : '默认昵称'
					this.saveUser({
						'username': this.userInfo.username
					})
				}
			},
			// onChooseNick(e){
			// 	console.log(e)
			// 	if(e.detail.pass){
			// 		this.saveUser({'username':this.userInfo.username})
			// 	}
			// },
			saveUser(data) {
				this.$api.default.request('user/saveUser', data).then((res) => {
					if (res.code == 1) {
						this.userInfo = res.user
						this.$common.successToShow(res.msg)
					} else {
						this.$common.errorToShow(res.msg)
					}
				})
			},
			change(e) {
				this.xuan = !this.xuan
				this.saveWriterUserConfig()
			},
		}
	}
</script>

<style lang="scss">
	page {
		background: rgba(242, 245, 242, 1);
	}

	.content {
		position: relative;
		padding: 40rpx 30rpx;

		.bei {
			width: 100%;
			height: 100vh;
			position: fixed;
			left: 0;
			top: 0;
			z-index: -1;
		}

		.top {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding-bottom: 20rpx;

			.head {
				width: 100rpx;
				height: 100rpx;
				border-radius: 50%;
			}

			.tocen {
				flex-grow: 1;
				padding: 0 12rpx;

				.nick {
					font-size: 28rpx;
					font-weight: bold;
					letter-spacing: 0em;
					color: #3D3D3D;
					padding-bottom: 4rpx;
				}

				.jibox {
					display: flex;
					align-items: center;

					.jipic {
						width: 41px;
						height:19px;
					}

					.biepic {
						width: 41px;
						height:19px;
						margin-left: 4px;
					}
				}
			}

			.zhu {
				width: 110rpx;
				height: 48rpx;
				border-radius: 18px;
				opacity: 1;
				background: #FFFFFF;
				flex-shrink: 0;
				display: flex;
				align-items: center;
				justify-content: flex-end;

				.zhutxt {
					font-size: 24rpx;
					letter-spacing: 0.08em;
					color: #3D3D3D;
				}

				.rar {
					margin-right: 8rpx;
					margin-left: -4rpx;
					width: 32rpx;
					height: 32rpx;
				}
			}
		}

		.shubox {
			display: flex;
			align-items: center;
			justify-content: center;
			padding-bottom: 20rpx;

			.shuli {
				width: 33%;
				text-align: center;

				.shutitle {
					font-size: 28rpx;
					line-height: 40rpx;
					color: #3D3D3D;
				}

				.shutxt {
					font-size: 20rpx;
					line-height: 28rpx;
					color: #999999;
				}
			}

			.line {
				width: 1px;
				background-color: #D8D8D8;
				height: 40rpx;
			}
		}

		.huibox {
			height: 120rpx;
			border-radius: 4px;
			background: linear-gradient(282deg, #45C4B0 -4%, #56E8B5 126%);
			margin-bottom: 20rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.left {
				flex-grow: 1;
				padding: 0 20rpx;

				.huititle {
					font-size: 28rpx;
					font-weight: bold;
					letter-spacing: 0em;
					color: #FFFFFF;
					text-shadow: 0px 8px 20px 0px #2EC28F;
					padding-bottom: 12rpx;
				}

				.huitxt {
					font-size: 20rpx;
					color: #FFFFFF;
					text-shadow: 0px 8px 20px 0px #2EC28F;
				}
			}

			.see {
				width: 124rpx;
				height: 40rpx;
				border-radius: 94px;
				opacity: 1;
				background: #FFFFFF;
				text-align: center;
				line-height: 40rpx;
				font-size: 20rpx;
				font-weight: bold;
				letter-spacing: 0.08em;
				color: #45C4B0;
				margin-right: 20rpx;
				flex-shrink: 0;
			}
		}

		.lanbox {
			background-color: #FFFFFF;
			border-radius: 10px;
			padding-top: 28rpx;
			display: flex;
			align-items: center;
			flex-wrap: wrap;
			margin-bottom: 20rpx;

			.lanli {
				text-align: center;
				width: 25%;
				padding-bottom: 40rpx;

				.lanpic {
					width: 88rpx;
					height: 84rpx;
					margin: 0 auto 0 -10rpx;
				}

				.lantxt {
					padding-top: 15rpx;
					font-size: 24rpx;
					letter-spacing: 0.08em;
					color: #999999;
				}
			}

			.gerenli {
				text-align: center;
				width: 33.33%;
				padding-bottom: 40rpx;

				.lanpic {
					width: 88rpx;
					height: 84rpx;
					margin: 0 auto;
				}

				.lantxt {
					padding-top: 15rpx;
					font-size: 24rpx;
					letter-spacing: 0.08em;
					color: #999999;
				}
			}
		}

		.adindex {
			padding: 0 36rpx 0 20rpx;
			height: 120rpx;
			border-radius: 4px;
			background: linear-gradient(180deg, #BABDCC 0%, #A9ABC3 100%);
			margin-bottom: 42rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.left {
				padding: 0 20rpx 0 0;

				.huititle {
					font-size: 28rpx;
					font-weight: bold;
					letter-spacing: 0em;
					color: #FFFFFF;
					text-shadow: 0px 8px 20px 0px #2EC28F;
					padding-bottom: 12rpx;
				}

				.huitxt {
					font-size: 20rpx;
					color: #FFFFFF;
					text-shadow: 0px 8px 20px 0px #2EC28F;
				}
			}
		}

		.isactive {
			background: linear-gradient(282deg, #45C4B0 -4%, #56E8B5 126%);
		}

		.qbox {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding-bottom: 24rpx;

			.qline {
				width: 4rpx;
				height: 28rpx;
				border-radius: 42px;
				opacity: 1;
				background: #45C4B0;
				flex-shrink: 0;
			}

			.qtitle {
				padding: 0 12rpx;
				flex-grow: 1;
				font-size: 28rpx;
				font-weight: bold;
				letter-spacing: 0em;
				color: #3D3D3D;
			}

			.seemore {
				font-size: 28rpx;
				font-weight: normal;
				text-align: center;
				letter-spacing: 0em;
				color: #999999;
			}
		}

		.dzBox {
			background-color: #FFFFFF;
			padding: 28rpx 30rpx 20rpx;
			border-radius: 16rpx;
			margin-bottom: 20rpx;

			.dztop {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding-bottom: 20rpx;
				border-bottom: 1px solid rgba(153, 153, 153, 0.1);

				.dzpic {
					width: 32rpx;
					height: 32rpx;
					flex-shrink: 0;
				}

				.dztxt {
					font-size: 28rpx;
					font-weight: bold;
					letter-spacing: 0em;
					color: #3D3D3D;
					flex-grow: 1;
					padding: 0 12rpx;
				}

				.jintxt {
					font-size: 20rpx;
					font-weight: bold;
					text-align: right;
					letter-spacing: 0em;
					color: #45C4B0;
				}
			}

			.uobox {
				padding-top: 20rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.uopic {
					width: 40rpx;
					height: 40rpx;
					border-radius: 50%;
					flex-shrink: 0;
				}

				.uotxt {
					padding: 0 8rpx;
					flex-grow: 1;
					font-size: 24rpx;
					font-weight: normal;
					letter-spacing: 0em;
					color: #999999;
				}

				.goup {
					width: 102rpx;
					height: 40rpx;
					border-radius: 94px;
					background: #45C4B0;
					text-align: center;
					line-height: 40rpx;
					font-size: 20rpx;
					font-weight: bold;
					letter-spacing: 0.08em;
					color: #FFFFFF;
				}
			}
		}
	}
</style>